package com.yuanrui.subject.domain.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * 线程池分配配置
 */
@Configuration
public class ThreadPoolConfig {
    /**
     * 标签线程池
     * @return 线程池
     * CallerRunsPolicy: 当线程池满了，直接在调用线程中执行: 由调用线程处理该任务
     * name: 线程池名称
     */
    @Bean(name = "labelThreadPool")
    public ThreadPoolExecutor getThreadPool() {
        return new ThreadPoolExecutor(10, 100, 5,
                TimeUnit.SECONDS,new LinkedBlockingDeque<>(40), new CustomNameThreadFactory("labelThreadPool"),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
